using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.IO.Compression;
using Microsoft.AnalysisServices.AdomdClient;
using Microsoft.ReportingServices.MDXQueryGenerator.ObjectModel;
using System.Xml;
using System.Linq;

namespace RetailAnalytic.Core
{
    public class PresentationAddhook
    {
        public PresentationBase presentationBase;
        private Presentation_adhook _presentation_adhook;
        public PresentationAddhook()
        {
            
        }
        public PresentationAddhook(PresentationBase PresentationBase)
        {
            presentationBase = PresentationBase;
            _presentation_adhook = GRetailAnalytic.Instance.radb.Presentation_adhooks.FirstOrDefault(c => c.ID == presentationBase.ClassTaskTask);
            if (_presentation_adhook != null)
            {
                _presentation_adhook.Name = presentationBase.ClassTaskName;
            }
        }
        public PresentationAddhook(PresentationBase PresentationBase, bool _IsNew)
        {
            if (_IsNew)
            {
                presentationBase = PresentationBase;
                try
                {
                    _presentation_adhook = new Presentation_adhook();
                    _presentation_adhook.Name = PresentationBase.ClassTaskName;
                    _presentation_adhook.bind = false;
                    _presentation_adhook.cubeName = "";
                    _presentation_adhook.DataSource = "";
                    _presentation_adhook.Desc = "";
                    _presentation_adhook.File = "";
                    _presentation_adhook.HTMLData = "";
                    _presentation_adhook.lCs = false;
                    _presentation_adhook.lCs1 = false;
                    _presentation_adhook.lCs2 = false;
                    _presentation_adhook.map = false;
                    _presentation_adhook.wb = false;
                    _presentation_adhook.XMLChart = "";
                    _presentation_adhook.XMLChart2 = "";
                    _presentation_adhook.XmlColorData = "";
                    _presentation_adhook.XMLData = "";
                    _presentation_adhook.XMLDesktop = "";
                    _presentation_adhook.XMLFilterData = "";
                    _presentation_adhook.XMLMeasureData = "";
                    GRetailAnalytic.Instance.radb.Presentation_adhooks.InsertOnSubmit(_presentation_adhook);
                    GRetailAnalytic.Instance.radb.SubmitChanges();
                    presentationBase.ClassTaskTask = _presentation_adhook.ID;
                }
                catch (Exception er) { }
            }
            else
            {
                presentationBase = PresentationBase;
                _presentation_adhook = GRetailAnalytic.Instance.radb.Presentation_adhooks.FirstOrDefault(c => c.ID == presentationBase.ClassTaskTask);
                if (_presentation_adhook != null)
                {
                    _presentation_adhook.Name = presentationBase.ClassTaskName;
                    _presentation_adhook.Desc = presentationBase.ClassTaskDescription;
                }
            }
            #region SaveOld
            //{
            //    _pHeader = _presentation;
            //    string sqlstr = "INSERT INTO RA.Presentation_adhook ([name]) VALUES (@name) " +
            //                    "SELECT Scope_identity()";
            //    SqlCommand _sqlcmd = new SqlCommand(sqlstr, SessionConfiguration.Dbconnection);
            //    _sqlcmd.Parameters.Add("@name", SqlDbType.Char).Value = _presentation.Name;
            //    _presentation.PresentationID = System.Convert.ToInt16(_sqlcmd.ExecuteScalar());
            //    GRetailAnalytic.Instance.HistoryLog.WriteLog(_pHeader.ClassTaskID, RetailAnalyticEnum.Event_Type.CREATE,"PRESENTATION_ADHOOK", "");
            //}
            //else _pHeader = _presentation;
            #endregion SaveOld
        }
        public Int32 CopyPresentation()
        {
            Presentation_adhook _pres = new Presentation_adhook();
            _pres.Name = this._presentation_adhook.Name;
            _pres.Desc = this._presentation_adhook.Desc;
            _pres.File = this._presentation_adhook.File;
            _pres.DataSource = this._presentation_adhook.DataSource;
            _pres.cubeName = this._presentation_adhook.cubeName;

            _pres.XMLData = this._presentation_adhook.XMLData;
            _pres.XMLChart = this._presentation_adhook.XMLChart;
            _pres.XMLChart2= this._presentation_adhook.XMLChart2;
            _pres.HTMLData = this._presentation_adhook.HTMLData;
            _pres.XMLDesktop = this._presentation_adhook.XMLDesktop;

            _pres.lCs = this._presentation_adhook.lCs;
            _pres.lCs1 = this._presentation_adhook.lCs1;
            _pres.lCs2 = this._presentation_adhook.lCs2;
            _pres.wb = this._presentation_adhook.wb;
            _pres.map = this._presentation_adhook.map;
            _pres.bind = this._presentation_adhook.bind;
            _pres.XmlColorData = this._presentation_adhook.XmlColorData;
            _pres.XMLFilterData = this._presentation_adhook.XMLFilterData;
            _pres.XMLMeasureData = this._presentation_adhook.XMLMeasureData;

            GRetailAnalytic.Instance.radb.Presentation_adhooks.InsertOnSubmit(_pres);
            Save();
            return _pres.ID;
        }

        #region New
        public void Save()
        {
            GRetailAnalytic.Instance.radb.SubmitChanges();
        }
        public void Delete()
        {
            if (_presentation_adhook != null)
            {
                GRetailAnalytic.Instance.radb.Presentation_adhooks.DeleteOnSubmit(this._presentation_adhook);
            }
            Save();
        }
        public byte[] CompressFile(string FileXML)
        {
            byte[] b = null;
            FileStream infile;
            try
            {
                #region Compess
                infile = new FileStream(FileXML, FileMode.Open, FileAccess.Read, FileShare.Read);
                byte[] buffer = new byte[infile.Length];
                int count = infile.Read(buffer, 0, buffer.Length);
                if (count != buffer.Length)
                {
                    infile.Close();
                }
                else
                {
                    infile.Close();
                    MemoryStream ms = new MemoryStream();
                    GZipStream compressedzipStream = new GZipStream(ms, CompressionMode.Compress, true);
                    compressedzipStream.Write(buffer, 0, buffer.Length);
                    compressedzipStream.Close();
                    b = new byte[ms.Length];
                    ms.Seek(0, SeekOrigin.Begin);
                    ms.Read(b, 0, b.Length);
                }
                #endregion Compess
            }
            catch
            {
            }
            return b;
        }
        public void SaveXml2File(string NamePre, string PathDir)
        {
            #region OLD
            //File.WriteAllText(pathFile, this.XMLData, Encoding.UTF8);
            //File.WriteAllText(pathFile.Replace(".xml", "Gr.xml"), this.XMLChart, Encoding.UTF8);


            //FileInfo _fl = new FileInfo(pathFile);
            //if (_fl.Exists)
            //{
            //    _fl.Delete();
            //}
            #endregion OLD
            Dictionary<string, byte[]> _Files = new Dictionary<string, byte[]>();
            #region Files
            string name = PathDir + "\\" + NamePre;
            //_fl.Name.Substring(0, _fl.Name.IndexOf(_fl.Extension));
            string F_XMLData = PathDir + "\\" + "name_pvt.xml";
            File.WriteAllText(F_XMLData, this.XMLData, Encoding.UTF8);
            _Files.Add(F_XMLData, CompressFile(F_XMLData));

            string F_XMLData_cs1 = PathDir + "\\" + "name_cs1.xml";
            File.WriteAllText(F_XMLData_cs1, this.XMLChart, Encoding.UTF8);
            _Files.Add(F_XMLData_cs1, CompressFile(F_XMLData_cs1));

            string F_XMLData_cs2 = PathDir + "\\" + "name_cs2.xml";
            File.WriteAllText(F_XMLData_cs2, this.XMLChart2, Encoding.UTF8);
            _Files.Add(F_XMLData_cs2, CompressFile(F_XMLData_cs2));

            string F_XMLData_flt = PathDir + "\\" + "name_flt.xml";
            File.WriteAllText(F_XMLData_flt, this.XMLFilterData, Encoding.UTF8);
            _Files.Add(F_XMLData_flt, CompressFile(F_XMLData_flt));

            string F_XMLData_cm = PathDir + "\\" + "name_cm.xml";
            File.WriteAllText(F_XMLData_cm, this.XMLMeasureData, Encoding.UTF8);
            _Files.Add(F_XMLData_cm, CompressFile(F_XMLData_cm));

            string F_XMLData_color = PathDir + "\\" + "name_color.xml";
            File.WriteAllText(F_XMLData_color, this.XMLColorData, Encoding.UTF8);
            _Files.Add(F_XMLData_color, CompressFile(F_XMLData_color));
            #endregion Files
            ZipFile.Xip_ClassFile.NewArchiveARH(NamePre, _Files);
        }
        public static int ReadAllBytesFromStream(Stream stream, byte[] buffer)
        {
            int totalCount = 0;
            // Use this method is used to read all bytes from a stream.
            int offset = 0;

            while (true)
            {
                int bytesRead = stream.Read(buffer, offset, 100);
                if (bytesRead == 0)
                {
                    break;
                }
                offset += bytesRead;
                totalCount += bytesRead;
            }
            return totalCount;
        }
        public string XMLData
        {
            get { return (this._presentation_adhook.XMLData == null) ? string.Empty : this._presentation_adhook.XMLData; }
            set { this._presentation_adhook.XMLData = value; Save(); }
        }
        public string XMLFilterData
        {
            get { return (this._presentation_adhook.XMLFilterData == null) ? string.Empty : this._presentation_adhook.XMLFilterData; }
            set { this._presentation_adhook.XMLFilterData = value; Save(); }
        }
        public string XMLChart
        {
            get { return (this._presentation_adhook.XMLChart == null) ? string.Empty : this._presentation_adhook.XMLChart; }
            set { this._presentation_adhook.XMLChart = value; Save(); }
        }
        public string XMLChart2
        {
            get { return (this._presentation_adhook.XMLChart2 == null) ? string.Empty : this._presentation_adhook.XMLChart2; }
            set { this._presentation_adhook.XMLChart2 = value; Save(); }
        }
        public string HTMLData
        {
            get { return (this._presentation_adhook.HTMLData == null) ? string.Empty : this._presentation_adhook.HTMLData; }
            set { this._presentation_adhook.HTMLData = value; Save(); }
        }
        public string XMLDesktop
        {
            get { return (this._presentation_adhook.XMLDesktop == null) ? string.Empty : this._presentation_adhook.XMLDesktop; }
            set { this._presentation_adhook.XMLDesktop = value; Save(); }
        }
        public string XMLMeasureData
        {
            get { return (this._presentation_adhook.XMLMeasureData == null) ? string.Empty : this._presentation_adhook.XMLMeasureData; }
            set { this._presentation_adhook.XMLMeasureData = value; Save(); }
        }
        public string XMLColorData
        {
            get { return (this._presentation_adhook.XmlColorData == null) ? string.Empty : this._presentation_adhook.XmlColorData; }
            set { this._presentation_adhook.XmlColorData = value; Save(); }
        }
        public bool lCs
        {
            get { return (this._presentation_adhook.lCs == null) ? false : (bool)this._presentation_adhook.lCs; }
            set { this._presentation_adhook.lCs = value; Save(); }
        }
        public bool lCs1
        {
            get { return (this._presentation_adhook.lCs1 == null) ? false : (bool)this._presentation_adhook.lCs1; }
            set { this._presentation_adhook.lCs1 = value; Save(); }
        }
        public bool lCs2
        {
            get { return (this._presentation_adhook.lCs2 == null) ? false : (bool)this._presentation_adhook.lCs2; }
            set { this._presentation_adhook.lCs2 = value; Save(); }
        }
        public bool wb
        {
            get { return (this._presentation_adhook.wb == null) ? false : (bool)this._presentation_adhook.wb; }
            set { this._presentation_adhook.wb = value; Save(); }
        }
        public bool map
        {
            get { return (this._presentation_adhook.map == null) ? false : (bool)this._presentation_adhook.map; }
            set { this._presentation_adhook.map = value; Save(); }
        }
        public bool bind
        {
            get { return (this._presentation_adhook.bind == null) ? false : (bool)this._presentation_adhook.bind; }
            set { this._presentation_adhook.bind = value; Save(); }
        }
        public string DataSource
        {
            get { return (this._presentation_adhook.DataSource == null) ? string.Empty : this._presentation_adhook.DataSource; }
            set { this._presentation_adhook.DataSource = value; Save(); }
        }
        public string LocalCube
        {
            get { return (this._presentation_adhook.File == null) ? string.Empty : this._presentation_adhook.File; }
            set { this._presentation_adhook.File = value; Save(); }
        }
        public string cubeName
        {
            get { return (this._presentation_adhook.cubeName == null) ? string.Empty : this._presentation_adhook.cubeName; }
            set { this._presentation_adhook.cubeName = value; Save(); }
        }
        #endregion New
    }
    public class PresentationKPI
    {
        public PresentationBase presentationBase;
        private Presentation_kpi _presentation_KPI;
        public PresentationKPI(PresentationBase PresentationBase)
        {
            presentationBase = PresentationBase;
            _presentation_KPI = GRetailAnalytic.Instance.radb.Presentation_kpis.FirstOrDefault(c => c.ID == presentationBase.ClassTaskTask);
            if (_presentation_KPI != null)
            {
                _presentation_KPI.name = presentationBase.ClassTaskName;
                _presentation_KPI.desc = presentationBase.ClassTaskDescription;
            }

        }
        public PresentationKPI(PresentationBase PresentationBase, bool _IsNew)
        {
            if (_IsNew)
            {
                presentationBase = PresentationBase;
                try
                {
                    _presentation_KPI = new Presentation_kpi();
                    _presentation_KPI.name = presentationBase.ClassTaskName;
                    _presentation_KPI.CubeName = "";
                    _presentation_KPI.DataSource = "";
                    _presentation_KPI.desc = "";
                    _presentation_KPI.includeKPIs = "";
                    _presentation_KPI.XMLData = "";
                    _presentation_KPI.XMLDesktop = "";
                    GRetailAnalytic.Instance.radb.Presentation_kpis.InsertOnSubmit(_presentation_KPI);
                    GRetailAnalytic.Instance.radb.SubmitChanges();
                    presentationBase.ClassTaskTask= _presentation_KPI.ID;
                }
                catch (Exception er) { }
            }
            else
            {
                presentationBase = PresentationBase;
                _presentation_KPI = GRetailAnalytic.Instance.radb.Presentation_kpis.FirstOrDefault(c => c.ID == presentationBase.ClassTaskTask);
                if (_presentation_KPI != null)
                {
                    _presentation_KPI.name = presentationBase.ClassTaskName;
                    _presentation_KPI.desc = presentationBase.ClassTaskDescription;
                }
            }
        }
        public Int32 CopyPresentation()
        {
            Presentation_kpi _pres = new Presentation_kpi();
            _pres.name = this._presentation_KPI.name;
            _pres.desc = this._presentation_KPI.desc;
            _pres.XMLData = this._presentation_KPI.XMLData;
            _pres.DataSource = this._presentation_KPI.DataSource;
            _pres.CubeName = this._presentation_KPI.CubeName;
            _pres.FilterXML = this._presentation_KPI.FilterXML;
            _pres.includeKPIs = this._presentation_KPI.includeKPIs;
            _pres.XMLDesktop = this._presentation_KPI.XMLDesktop;
            GRetailAnalytic.Instance.radb.Presentation_kpis.InsertOnSubmit(_pres);
            Save();
            return _pres.ID;
        }

        #region New
        public void Save()
        {
            GRetailAnalytic.Instance.radb.SubmitChanges();
        }
        public void Delete()
        {
            if (_presentation_KPI != null)
            {
                GRetailAnalytic.Instance.radb.Presentation_kpis.DeleteOnSubmit(this._presentation_KPI);
            }
            Save();
        }
        public string XMLData
        {
            get { return (this._presentation_KPI.XMLData == null) ? string.Empty : this._presentation_KPI.XMLData; }
            set { this._presentation_KPI.XMLData = value; Save(); }
        }
        public string XMLDesktop
        {
            get { return (this._presentation_KPI.XMLDesktop == null) ? string.Empty : this._presentation_KPI.XMLDesktop; }
            set { this._presentation_KPI.XMLDesktop = value; Save(); }
        }
        public string FilterXML
        {
            get { return (this._presentation_KPI.FilterXML == null) ? string.Empty : this._presentation_KPI.FilterXML; }
            set { this._presentation_KPI.FilterXML = value; Save(); }
        }
        public string includeKPIs
        {
            get { return (this._presentation_KPI.includeKPIs == null) ? string.Empty : this._presentation_KPI.includeKPIs; }
            set { this._presentation_KPI.includeKPIs = value; Save(); }
        }
        public string DataSource
        {
            get { return (this._presentation_KPI.DataSource == null) ? string.Empty : this._presentation_KPI.DataSource; }
            set { this._presentation_KPI.DataSource = value; Save(); }
        }
        public string cubeName
        {
            get { return (this._presentation_KPI.CubeName == null) ? string.Empty : this._presentation_KPI.CubeName; }
            set { this._presentation_KPI.CubeName = value; Save(); }
        }
        #endregion New
    }
    public class PresentationDM
    {
        public PresentationBase presentationBase;
        private Presentation_DM _presentation_DM;
        public PresentationDM(PresentationBase PresentationBase)
        {
            presentationBase = PresentationBase;
            _presentation_DM = GRetailAnalytic.Instance.radb.Presentation_DMs.FirstOrDefault(c => c.ID == presentationBase.ClassTaskTask);
            if (_presentation_DM != null)
            {
                _presentation_DM.Name = presentationBase.ClassTaskName;
                _presentation_DM.Desc = presentationBase.ClassTaskDescription;
            }

        }
        public PresentationDM(PresentationBase PresentationBase, bool _IsNew)
        {
            if (_IsNew)
            {
                presentationBase = PresentationBase;
                try
                {
                    _presentation_DM = new Presentation_DM();
                    _presentation_DM.Name = presentationBase.ClassTaskName;
                    _presentation_DM.Desc = "";
                    _presentation_DM.DataSource = "";
                    _presentation_DM.cubeName = "";
                    _presentation_DM.MiningStructure = "";
                    _presentation_DM.IncludedDMmodel = "";
                    GRetailAnalytic.Instance.radb.Presentation_DMs.InsertOnSubmit(_presentation_DM);
                    GRetailAnalytic.Instance.radb.SubmitChanges();
                    presentationBase.ClassTaskTask = _presentation_DM.ID;
                }
                catch (Exception er) { }
            }
            else
            {
                presentationBase = PresentationBase;
                _presentation_DM = GRetailAnalytic.Instance.radb.Presentation_DMs.FirstOrDefault(c => c.ID == presentationBase.ClassTaskTask);
                if (_presentation_DM != null)
                {
                    _presentation_DM.Name = presentationBase.ClassTaskName;
                    _presentation_DM.Desc = presentationBase.ClassTaskDescription;
                }
            }
        }
        public Int32 CopyPresentation()
        {
            Presentation_DM _pres = new Presentation_DM();
            _pres.Name = this._presentation_DM.Name;
            _pres.Desc = this._presentation_DM.Desc;
            _pres.DataSource = this._presentation_DM.DataSource;
            _pres.cubeName = this._presentation_DM.cubeName;
            _pres.MiningStructure = this._presentation_DM.MiningStructure;
            _pres.MiningModel = this._presentation_DM.MiningModel;
            _pres.IncludedDMmodel = this._presentation_DM.IncludedDMmodel;
            GRetailAnalytic.Instance.radb.Presentation_DMs.InsertOnSubmit(_pres);
            Save();
            return _pres.ID;
        }

        #region New
        public void Save()
        {
            GRetailAnalytic.Instance.radb.SubmitChanges();
        }
        public void Delete()
        {
            if (_presentation_DM != null)
            {
                GRetailAnalytic.Instance.radb.Presentation_DMs.DeleteOnSubmit(this._presentation_DM);
            }
            Save();
        }
        public string MiningStructure
        {
            get { return (this._presentation_DM.MiningStructure == null) ? string.Empty : this._presentation_DM.MiningStructure; }
            set { this._presentation_DM.MiningStructure = value; Save(); }
        }
        public Int32 MiningModel
        {
            get { return (this._presentation_DM.MiningModel == null) ? 0 : (int)this._presentation_DM.MiningModel; }
            set { this._presentation_DM.MiningModel = value; Save(); }
        }
        public string DataSource
        {
            get { return (this._presentation_DM.DataSource == null) ? string.Empty : this._presentation_DM.DataSource; }
            set { this._presentation_DM.DataSource = value; Save(); }
        }
        public string IncludedDMmodel
        {
            get { return (this._presentation_DM.IncludedDMmodel == null) ? string.Empty : this._presentation_DM.IncludedDMmodel; }
            set { this._presentation_DM.IncludedDMmodel = value; Save(); }
        }
        public string cubeName
        {
            get { return (this._presentation_DM.cubeName == null) ? string.Empty : this._presentation_DM.cubeName; }
            set { this._presentation_DM.cubeName = value; Save(); }
        }
        #endregion New
    }
    public class PresentationRS
    {
        public PresentationBase presentationBase;
        private Presentation_REPBUILDER _presentation_REPBLD;
        public PresentationRS(PresentationBase PresentationBase)
        {
            presentationBase = PresentationBase;
            _presentation_REPBLD = GRetailAnalytic.Instance.radb.Presentation_REPBUILDERs.FirstOrDefault(c => c.ID == presentationBase.ClassTaskTask);
            if (_presentation_REPBLD != null)
            {
                _presentation_REPBLD.Name = presentationBase.ClassTaskName;
            }
        }
        public PresentationRS(PresentationBase PresentationBase, bool _IsNew)
        {
            if (_IsNew)
            {
                presentationBase = PresentationBase;
                try
                {
                    _presentation_REPBLD = new Presentation_REPBUILDER();
                    _presentation_REPBLD.Name = presentationBase.ClassTaskName;
                    _presentation_REPBLD.ReportPath = "";
                    _presentation_REPBLD.RepServer = "";
                    _presentation_REPBLD.DataSource = "";
                    GRetailAnalytic.Instance.radb.Presentation_REPBUILDERs.InsertOnSubmit(_presentation_REPBLD);
                    GRetailAnalytic.Instance.radb.SubmitChanges();
                    presentationBase.ClassTaskTask = _presentation_REPBLD.ID;
                }
                catch (Exception er) { }
            }
            else
            {
                presentationBase = PresentationBase;
                _presentation_REPBLD = GRetailAnalytic.Instance.radb.Presentation_REPBUILDERs.FirstOrDefault(c => c.ID == presentationBase.ClassTaskTask);
                if (_presentation_REPBLD != null)
                {
                    _presentation_REPBLD.Name = presentationBase.ClassTaskName;
                }
            }
            #region SaveOld
            //{
            //    _pHeader = _presentation;
            //    string sqlstr = "INSERT INTO RA.Presentation_REPBUILDER ([name]) VALUES (@name) " +
            //                    "SELECT Scope_identity()";
            //    SqlCommand _sqlcmd = new SqlCommand(sqlstr, SessionConfiguration.Dbconnection);
            //    _sqlcmd.Parameters.Add("@name", SqlDbType.Char).Value = _presentation.Name;
            //    _presentation.PresentationID = System.Convert.ToInt16(_sqlcmd.ExecuteScalar());
            //    GRetailAnalytic.Instance.HistoryLog.WriteLog(_pHeader.ClassTaskID, RetailAnalyticEnum.Event_Type.CLOSE,"PRESENTATION_REPBUILDER", "");
            //}
            //else _pHeader = _presentation;
            #endregion SaveOld
        }
        public Int32 CopyPresentation()
        {
            Presentation_REPBUILDER _pres = new Presentation_REPBUILDER();
            _pres.Name = this._presentation_REPBLD.Name;
            _pres.DataSource = this._presentation_REPBLD.DataSource;
            _pres.RepServer = this._presentation_REPBLD.RepServer;
            _pres.ReportPath = this._presentation_REPBLD.ReportPath;
            GRetailAnalytic.Instance.radb.Presentation_REPBUILDERs.InsertOnSubmit(_pres);
            Save();
            return _pres.ID;
        }

        #region New
        public void Save()
        {
            GRetailAnalytic.Instance.radb.SubmitChanges();
        }
        public void Delete()
        {
            if (_presentation_REPBLD != null)
            {
                GRetailAnalytic.Instance.radb.Presentation_REPBUILDERs.DeleteOnSubmit(this._presentation_REPBLD);
            }
            Save();
        }
        public string RepServer
        {
            get { return (this._presentation_REPBLD.RepServer == null) ? string.Empty : this._presentation_REPBLD.RepServer; }
            set { this._presentation_REPBLD.RepServer = value; Save(); }
        }
        public string ReportPath
        {
            get { return (this._presentation_REPBLD.ReportPath == null) ? string.Empty : this._presentation_REPBLD.ReportPath; }
            set { this._presentation_REPBLD.ReportPath = value; Save(); }
        }
        public string DataSource
        {
            get { return (this._presentation_REPBLD.DataSource == null) ? string.Empty : this._presentation_REPBLD.DataSource; }
            set { this._presentation_REPBLD.DataSource = value; Save(); }
        }
        #endregion New
    }
    public class PresentationMap
    {
        public PresentationBase presentationBase;
        private Presentation_Map _presentation_Map;
        public PresentationMap(PresentationBase PresentationBase)
        {
            presentationBase = PresentationBase;
            _presentation_Map = GRetailAnalytic.Instance.radb.Presentation_Maps.FirstOrDefault(c => c.ID == presentationBase.ClassTaskTask);
            if (_presentation_Map != null)
            {
                _presentation_Map.Name = presentationBase.ClassTaskName;
            }
        }
        public PresentationMap(PresentationBase PresentationBase, bool _IsNew)
        {
            if (_IsNew)
            {
                presentationBase = PresentationBase;
                try
                {
                    _presentation_Map = new Presentation_Map();
                    _presentation_Map.Name = presentationBase.ClassTaskName;
                    _presentation_Map.XMLFilterData = "";
                    _presentation_Map.XMLConfiguration = "";
                    _presentation_Map.XMLKpiData = "";
                    _presentation_Map.XMLMeasureColoringData = "";
                    _presentation_Map.XMLMeasureData = "";
                    _presentation_Map.XMLTypeVisualizeMeasures = "";
                    _presentation_Map.cubeName = "";
//                    _presentation_Map.Name = "";
                    _presentation_Map.ReportBinds = 0;
                    GRetailAnalytic.Instance.radb.Presentation_Maps.InsertOnSubmit(_presentation_Map);
                    Save();
                    presentationBase.ClassTaskTask = _presentation_Map.ID;
                    //GRetailAnalytic.Instance.HistoryLog.WriteLog(_pHeader.ClassTaskID, RetailAnalyticEnum.Event_Type.CREATE, "PRESENTATION_MAP", "");
                }
                catch (Exception er) { }
            }
            else
            {
                presentationBase = PresentationBase;
                _presentation_Map = GRetailAnalytic.Instance.radb.Presentation_Maps.FirstOrDefault(c => c.ID == presentationBase.ClassTaskTask);
                if (_presentation_Map != null)
                {
                    _presentation_Map.Name = presentationBase.ClassTaskName;
                }
            }
        }
        public Int32 CopyPresentation()
        {
            Presentation_Map _pres = new Presentation_Map();
            _pres.Name = this._presentation_Map.Name;
            _pres.DataSource = this._presentation_Map.DataSource;
            _pres.XMLFilterData = this._presentation_Map.XMLFilterData;
            _pres.XMLConfiguration = this._presentation_Map.XMLConfiguration;
            _pres.XMLKpiData = this._presentation_Map.XMLKpiData;
            _pres.Map_ID = this._presentation_Map.Map_ID;
            _pres.Map = this._presentation_Map.Map;
            _pres.XMLMeasureColoringData = this._presentation_Map.XMLMeasureColoringData;
            _pres.XMLMeasureData = this._presentation_Map.XMLMeasureData;
            _pres.XMLTypeVisualizeMeasures = this._presentation_Map.XMLTypeVisualizeMeasures;
            _pres.cubeName = this._presentation_Map.cubeName;
            _pres.ReportBinds = this._presentation_Map.ReportBinds;
            GRetailAnalytic.Instance.radb.Presentation_Maps.InsertOnSubmit(_pres);
            Save();
            return _pres.ID;
        }
        #region New
        public void Save()
        {
            GRetailAnalytic.Instance.radb.SubmitChanges();
        }
        public void Delete()
        {
            if (_presentation_Map != null)
            {
                GRetailAnalytic.Instance.radb.Presentation_Maps.DeleteOnSubmit(this._presentation_Map);
            }
            Save();
        }
        public string DataSource
        {
            get { return (this._presentation_Map.DataSource == null) ? string.Empty : this._presentation_Map.DataSource; }
            set { this._presentation_Map.DataSource = value; Save(); }
        }
        public string cubeName
        {
            get { return (this._presentation_Map.cubeName == null) ? string.Empty : this._presentation_Map.cubeName; }
            set { this._presentation_Map.cubeName = value; Save(); }
        }
        public string XMLFilterData
        {
            get { return (this._presentation_Map.XMLFilterData == null) ? string.Empty : this._presentation_Map.XMLFilterData; }
            set { this._presentation_Map.XMLFilterData = value; Save(); }
        }
        public string XMLTypeVisualizeMeasures
        {
            get { return (this._presentation_Map.XMLTypeVisualizeMeasures == null) ? string.Empty : this._presentation_Map.XMLTypeVisualizeMeasures; }
            set { this._presentation_Map.XMLTypeVisualizeMeasures = value; Save(); }
        }
        public string XMLMeasureData
        {
            get { return (this._presentation_Map.XMLMeasureData == null) ? string.Empty : this._presentation_Map.XMLMeasureData; }
            set { this._presentation_Map.XMLMeasureData = value; Save(); }
        }
        public string XMLMeasureColoringData
        {
            get { return (this._presentation_Map.XMLMeasureColoringData == null) ? string.Empty : this._presentation_Map.XMLMeasureColoringData; }
            set { this._presentation_Map.XMLMeasureColoringData = value; Save(); }
        }
        public string XMLConfiguration
        {
            get { return (this._presentation_Map.XMLConfiguration == null) ? string.Empty : this._presentation_Map.XMLConfiguration; }
            set { this._presentation_Map.XMLConfiguration = value; Save(); }
        }
        public string XMLKpiData
        {
            get { return (this._presentation_Map.XMLKpiData == null) ? string.Empty : this._presentation_Map.XMLKpiData; }
            set { this._presentation_Map.XMLKpiData = value; Save(); }
        }
        public byte[] Map
        {
            get { return this._presentation_Map.Map.ToArray(); }
            set { this._presentation_Map.Map = value; Save(); }
        }
        public Int32 ReportBinds
        {
            get { return (this._presentation_Map.ReportBinds == null) ? 0 : (int)this._presentation_Map.ReportBinds; }
            set { this._presentation_Map.ReportBinds = value; Save(); }
        }
        public Int32 Map_ID
        {
            get { return (this._presentation_Map.Map_ID == null) ? 0 : (int)this._presentation_Map.Map_ID; }
            set { this._presentation_Map.Map_ID = value; Save(); }
        }
        #endregion New
    }
}
